﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using UniFTP.Server;
using System.IO;

namespace App2Wpf.FileServer
{
    public class ftpServer
    {
        public static void Start()
        {

            FtpServer f = new FtpServer(port: 8022, enableIPv6: false,  logHeader: "UniFTP");

            string currentFtpDir = Path.Combine(System.Environment.CurrentDirectory,"ftpServer");
            if (!Directory.Exists(currentFtpDir)) Directory.CreateDirectory(currentFtpDir);

            f.Config = new FtpConfig(currentFtpDir, welcome: new string[] { "By Ulysses" });
            //Load configs...
            f.LoadConfigs();
            //or add configs manually
            //f.AddUserGroup("test", AuthType.Password);
            //f.AddGroupRule("test", "/", "rwxrwxrwx");
            //f.AddUser("root", "test", "test");

            //Import SSL cert
            f.ImportCertificate("UniFTP.Open.pfx", null);
            //Log event
            f.OnLog += sender => Console.WriteLine(((FtpLogEntry)sender).ToString());

            f.Config.LogInWelcome = new string[] { "Welcome back,Commander." };

            //Add directory/file link
            f.AddLink("test", "M:\\ACGMusic", "/");
            f.AddGroupRule("test", "/Music", "r-xr-xr-x");

            f.Start();
            //Console.WriteLine("UniFTP Server Started!");
            //Console.ReadLine();
            //f.Stop();
            //Save configs for next time
            //f.SaveConfigs();
            return;
        }
    }
}
